Yo-yo Problem
   HOME

TheInfoList



OR:

In software development, the yo-yo problem is an
anti-pattern An anti-pattern in software engineering, project management, and business processes is a common response to a recurring problem that is usually ineffective and risks being highly counterproductive. The term, coined in 1995 by computer programmer An ...
that occurs when a programmer has to read and understand a program whose inheritance graph is so long and complicated that the programmer has to keep flipping between many different class definitions in order to follow the control flow of the program. It is most often seen in the context of
object-oriented programming Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
. The term comes from comparing the bouncing attention of the programmer to the up-down movement of a toy
yo-yo A yo-yo (also spelled yoyo) is a toy consisting of an axle connected to two disks, and a string looped around the axle, similar to a spool. It is an ancient toy with proof of existence since 500 BCE. The yo-yo was also called a bandalore in ...
. Taenzer, Ganti, and Podar described the problem by name, explaining: "Often we get the feeling of riding a
yoyo A yo-yo (also spelled yoyo) is a toy consisting of an axle connected to two disks, and a string looped around the axle, similar to a spool. It is an ancient toy with proof of existence since 500 BCE. The yo-yo was also called a bandalore in ...
when we try to understand one of these message trees." Most practices of object-oriented programming recommend keeping the inheritance graph as shallow as possible, in part to avoid this problem. The use of
composition Composition or Compositions may refer to: Arts and literature *Composition (dance), practice and teaching of choreography *Composition (language), in literature and rhetoric, producing a work in spoken tradition and written discourse, to include v ...
instead of
inheritance Inheritance is the practice of receiving private property, titles, debts, entitlements, privileges, rights, and obligations upon the death of an individual. The rules of inheritance differ among societies and have changed over time. Officia ...
is also strongly preferred, although this still requires that a programmer keep multiple class definitions in mind at once. Deep hierarchies are a
code smell In computer programming, a code smell is any characteristic in the source code of a program that possibly indicates a deeper problem. Determining what is and is not a code smell is subjective, and varies by language, developer, and development meth ...
and a symptom of sub-classification for
code reuse In software development (and computer programming in general), code reuse, also called software reuse, is the use of existing software, or software knowledge, to build new software, following the reusability principles. Code reuse may be achie ...
. More generally, the yo-yo problem can also refer to any situation where a person must keep flipping between different sources of information in order to understand a concept. There are several code refactor techniques to flatten these hierarchies without compromising the overall behavior. Object-oriented design techniques such as documenting
layer Layer or layered may refer to: Arts, entertainment, and media * ''Layers'' (Kungs album) * ''Layers'' (Les McCann album) * ''Layers'' (Royce da 5'9" album) *"Layers", the title track of Royce da 5'9"'s sixth studio album * Layer, a female Maveri ...
s of the inheritance hierarchy can reduce the effect of this problem, as they collect in one place the information that the programmer is required to understand.


See also

* * Complexity What it means for a system (of any sort) to be complex * Hrair limit The suggestion that humans can entertain at most approximately seven concepts at once *
Implementation inheritance In object-oriented programming, inheritance is the mechanism of basing an object or class upon another object ( prototype-based inheritance) or class ( class-based inheritance), retaining similar implementation. Also defined as deriving new classe ...
*
Inheritance semantics In object-oriented programming, behavioral subtyping is the principle that subclasses should satisfy the expectations of clients accessing subclass objects through references of superclass type, not just as regards syntactic safety (such as the abs ...
* Virtual Inheritance (object-oriented programming) *
Code Smell In computer programming, a code smell is any characteristic in the source code of a program that possibly indicates a deeper problem. Determining what is and is not a code smell is subjective, and varies by language, developer, and development meth ...


References

{{Reflist Object-oriented programming Anti-patterns